package com.ljw.servlet_springMVC.annotation.intercept;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @FileName MyIntercept
 * @Description TODO
 * @Author ljw
 * @Date 2021/2/6 3:09
 * @Version 1.0
 */
public class MyIntercept implements HandlerInterceptor {
    //进入controller类方法之前的操作，若返回true，则可执行postHandle（）和 afterCompletion（）方法
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle----------"+request.getRequestURI());
        return true;
    }

    //controller类方法执行完返回view前，执行下面方法
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle----------");
    }

    //controller类方法完全执行完毕后（页面响应后），执行下面方法
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion----------");
    }
}
